
#include "PDTNode.h"
#include "PDTCodeGraph.h"
#include "PDTGraphVisitor.h"

PDTNode::PDTNode(PDTCodeGraph & CG){
	CG.addNode(this);
    id=CG.currentId;
    CG.updateCurrentId();
}
NodeId PDTNode::getId(){
	return id;
}

vector<PDTNode*> * PDTNode::getReaders(){
	return (&readers);
}

vector<PDTNode*> * PDTNode::getWriters(){
	return (&writers);
}


void PDTNode::addWriter(PDTNode * writer){
	writers.push_back(writer);
}

void PDTNode::addReader(PDTNode * reader){
	readers.push_back(reader);
}

vector<PDTNode*> *  PDTNode::getParents(){
	return (&parents);
}

vector<PDTNode*> * PDTNode::getChildren(){
	return (&children);
}

void  PDTNode::addParent(PDTNode* parent){
	parents.push_back(parent);
}

void  PDTNode::addChild(PDTNode* child){
	children.push_back(child);
}


void PDTNode::traverse(PDTGraphVisitor &gv){
	(&gv)->pre(this);
	//printType();cout<<endl;///visitor functions

	vector<PDTNode*> *children=this->getChildren();
	vector <PDTNode*> newGraph;

	for (unsigned int i=0;i<children->size();i++)
	{
		PDTNode * child=((*children)[i]);
	//	cout<<"size "<<children->size()<<endl;
		child->traverse(gv);
		(&gv)->in(this,child,i);

	}
	(&gv)->post(this);

}

PDTNode::~PDTNode(){

 }
